<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>baidu map api demo</title>
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?key=5f60d7b28e2f6dc805c263bc1d524f61&v=1.1&services=true"></script>
	</head>
	<body>
		<div id="baiduMap-demo" >
			<label for="txtCity">City:</label>
			<input type="text" id="txtCity"/>
			<label for="txtPlace">Place</label>>
			<input type="text" id="txtPlace" size="50"/>
			<button id="btnSearch">Search</button>
			<div id="mapWrap" style="width:800px;height:480px;margin-top:20px;"></div>
		</div>
		
		<script type="text/javascript">
			/*
			var local = new BMap.LocalSearch(map, {
			  renderOptions:{map: map}
			});
			local.search("天安门");
			*/
		//<![CDATA[
		(function($){
			window.map=new BMap.Map("mapWrap");
			window.geo=new BMap.Geocoder();
			var $city=$("#txtCity"),$place=$("#txtPlace"),city="",place="";
			$("#btnSearch").click(function(){
				if((city=$city.val())==""){
					$city.css("background-color","red");return;
				};
				$city.css("background-color","green");
				
				place=$place.val();
				place=place==""?city:place;
				
				// 查找城市坐标,将地址解析结果显示在地图上，并调整地图视野  
				geo.getPoint(place, function(point){  
					if (point) {  
						map.centerAndZoom(point, 16);  
				     	map.addOverlay(new BMap.Marker(point));  
				   	};  
				 }, city);   
			});
		})(jQuery);
		//]]>
		</script> 
		
	</body>
</html>
